import java.util.GregorianCalendar;
import java.util.*;
/**
 * @Author: Lenovo
 * @Date: 2024/6/8 12:39
 * @description:
 */
public class TestCalendar {
    public static void main(String[] args) {
        GregorianCalendar calendar=new GregorianCalendar
                (2024,6,8,12,40,00);
        System.out.println(calendar);
        int year=calendar.get(Calendar.YEAR);
        int month=calendar.get(Calendar.MONTH);
        int day=calendar.get(Calendar.DAY_OF_MONTH);
        int day2=calendar.get(Calendar.DATE);
        // 日：Calendar.DATE和Calendar.DAY_OF_MONTH同义
        int date = calendar.get(Calendar.DAY_OF_WEEK);
        // 星期几 这里是：1-7.周日是1，周一是2，。。。周六是7
        System.out.println(year);
        System.out.println(month);
        System.out.println(day);
        System.out.println(day2);
        System.out.println(date);

        //设置日期
        GregorianCalendar calendar1=new GregorianCalendar();
        calendar1.set(Calendar.YEAR,2000);
        calendar1.set(Calendar.MONTH,1);
        calendar1.set(Calendar.DATE,25);
        calendar1.set(Calendar.HOUR_OF_DAY,8);
        calendar1.set(Calendar.MINUTE,10);
        calendar1.set(Calendar.SECOND,10);

        //日期的计算
        GregorianCalendar calendar2=new GregorianCalendar
                (2024,6,8,12,40,00);
        calendar2.add(Calendar.MONTH,-7);
        calendar2.add(Calendar.DATE,7);
        printCalendar(calendar2);
        // 日历对象和时间对象转化
        Date d = calendar2.getTime();
        GregorianCalendar calendar4 = new GregorianCalendar();
        calendar4.setTime(new Date());
    }
    static void printCalendar(Calendar calendar) {
        int year = calendar.get(Calendar.YEAR);
        int month = calendar.get(Calendar.MONTH) + 1;
        int day = calendar.get(Calendar.DAY_OF_MONTH);
        int date = calendar.get(Calendar.DAY_OF_WEEK) - 1; // 星期几
        String week = "" + ((date == 0) ? "日" : date);
        int hour = calendar.get(Calendar.HOUR);
        int minute = calendar.get(Calendar.MINUTE);
        int second = calendar.get(Calendar.SECOND);
        System.out.printf("%d年%d月%d日,星期%s %d:%d:%d\n", year, month, day,
                week, hour, minute, second);
    }
}
